package com.enjoyor.soa.traffic.server.tsms.dubbo.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.enjoyor.soa.traffic.api.dto.tsms.SchemeInfoDto;
import com.enjoyor.soa.traffic.api.service.dubbo.tsms.IDubboSchemeInfoService;
import com.enjoyor.soa.traffic.core.tsms.domain.SchemeInfo;
import com.enjoyor.soa.traffic.core.tsms.service.IRouteInfoService;
import com.enjoyor.soa.traffic.core.tsms.service.ISchemeInfoService;
import com.enjoyor.soa.traffic.server.tsms.helper.EntityChangeHelper;
import com.enjoyor.soa.traffic.util.enums.EnumAppCode;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

@SuppressWarnings("rawtypes")
@Service(version = "1.0.0", timeout = 4000)
public class DubboSchemeInfoService implements IDubboSchemeInfoService{

	@Autowired
	private ISchemeInfoService iSchemeInfoService;
	@Override
	public ResultPojo getSchemeInfoPage(Page page, String schemeId, String schemeName, String schemeBeginDate,
			String schemeEndDate, String schemeRankId, String schemeStatusId) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo = new ResultPojo(iSchemeInfoService.getSchemeInfoPage(page, schemeId, schemeName,
				schemeBeginDate, schemeEndDate, schemeRankId, schemeStatusId));
		return resultPojo;
	}

	@Override
	public ResultPojo getSchemeInfoList(String schemeId, String schemeName, String schemeBeginDate,
			String schemeEndDate, String schemeRankId, String schemeStatusId, Boolean isFull) {
		// TODO Auto-generated method stub
		List<SchemeInfo> schemeInfoList = iSchemeInfoService.getSchemeInfoList(schemeId, schemeName, schemeBeginDate,
				schemeEndDate, schemeRankId, schemeStatusId, isFull);
		List<SchemeInfoDto> schemeInfoDtoList = EntityChangeHelper.schemePojoToDtoList(schemeInfoList);
		ResultPojo resultPojo = new ResultPojo(schemeInfoDtoList);
		return resultPojo;
	}

	@Override
	public ResultPojo insertSchemeInfo(SchemeInfoDto shcemeInfoDto,String personName) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo = new ResultPojo();
		//List<SchemeFile> fileList = DomainUtil.merge2ListJson(shcemeInfoDto.getSchemeFileList(), SchemeFile.class);
		//SchemeInfo schemeInfo = ReflectHelper.beanToBean(shcemeInfoDto, SchemeInfo.class);
		//schemeInfo.setSchemeFileList(fileList);
		SchemeInfo schemeInfo = EntityChangeHelper.schemeDtoToPojo(shcemeInfoDto);
		String schemeId = iSchemeInfoService.insert(schemeInfo, personName);
		if( !"false".equals(schemeId) ) {
			resultPojo = new ResultPojo(schemeId);
		}else {
			resultPojo = new ResultPojo(EnumAppCode.DEVIALTE_UNIQUE, "方案编号已存在！");
		}
		return resultPojo;
	}

	@Override
	public ResultPojo updeteSchemeInfo(SchemeInfoDto shcemeInfoDto,String personName) {
		// TODO Auto-generated method stub
		SchemeInfo schemeInfo = EntityChangeHelper.schemeDtoToPojo(shcemeInfoDto);
		iSchemeInfoService.update(schemeInfo, personName);
		return new ResultPojo();
	}

	@Override
	public ResultPojo deleteSchemeInfo(String schemeId,String personName) {
		// TODO Auto-generated method stub
		iSchemeInfoService.delete(schemeId, personName);
		return new ResultPojo();
	}

	@Override
	public ResultPojo submitSchemeInfo(String schemeId, String personName) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo = new ResultPojo();
		Boolean flag = iSchemeInfoService.commit(schemeId, personName);
		if(flag) {
			resultPojo = new ResultPojo("提交成功！");
		}else {
			resultPojo = new ResultPojo(EnumAppCode.PARAM_NULL, "方案编号参数为空！");
		}
		return resultPojo;
	}

	@Override
	public ResultPojo auditSchemeInfo(String schemeId,String schemeStatusId, String checkIdea, String personName) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo = new ResultPojo();
		Boolean flag = iSchemeInfoService.audit(schemeId, schemeStatusId, checkIdea,personName);
		if(flag) {
			resultPojo = new ResultPojo("审核成功！");
			//审核成功之后  推送岗位消息到勤务系统进行排班……
			
		}else {
			resultPojo = new ResultPojo(EnumAppCode.PARAM_ERR, "审核状态参数错误！");
		}
		return resultPojo;
	}

	@Override
	public ResultPojo getSchemeForWeek(String schemeId, String schemeBeginDate, String schemeEndDate, String executeStatusId, 
			String driverPoliceId, String beforeLicensePlate) {
		// TODO Auto-generated method stub
		List list2 = iSchemeInfoService.getSchemeInfoForWeek(schemeId, schemeBeginDate, schemeEndDate, executeStatusId, 
				driverPoliceId, beforeLicensePlate);
		ResultPojo resultPojo = new ResultPojo();
		resultPojo.setResultList(list2);
		return resultPojo;
	}
	
	@Override
	public ResultPojo editSchemeWaitStatus(String executeTaskId, String isWaitExecute, String personName) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo = new ResultPojo();
		Boolean flag = iSchemeInfoService.editSchemeWaitStatus(executeTaskId, isWaitExecute, personName);
		if(flag) {
			resultPojo = new ResultPojo("待执行状态修改成功！");
		}else {
			resultPojo = new ResultPojo(EnumAppCode.PARAM_ERR, "待执行状态参数错误！");
		}
		return resultPojo;
	}

	@Override
	public ResultPojo getPreviewSchemeList(String schemeBeginDate, String schemeEndDate) {
		// TODO Auto-generated method stub
		List list2 = iSchemeInfoService.getPreviewSchemeList(schemeBeginDate, schemeEndDate, true);
		ResultPojo resultPojo = new ResultPojo();
		resultPojo.setResultList(list2);
		return resultPojo;
	}
	
	/**
	 * 实际执行开始时间查询
	 * @param taskId 任务编号
	 * @param schemeId 方案编号
	 * @param executeTaskId 执行任务编号
	 * @param executeDate 执行日期
	 * @return
	 */
	public ResultPojo getExecuteStatusCollect(String taskId, String schemeId, String executeTaskId, 
			String executeDate) {
		ResultPojo resultPojo = new ResultPojo();
		List<Map<String, Object>> executeStatusList = iSchemeInfoService.getExecuteStatusCollect(taskId, schemeId, 
				executeTaskId, executeDate);
		resultPojo.setResultList(executeStatusList);
		return resultPojo;
	}
	
	/**
	 * 执行任务数量统计 
	 * @param taskId 任务编号
	 * @param schemeId 方案编号
	 * @param executeTaskId 执行任务编号
	 * @param executeDate 执行日期
	 * @return
	 */
	public ResultPojo getRealExecuteTime(String taskId, String schemeId, String executeTaskId, 
			String executeDate) {
		ResultPojo resultPojo = new ResultPojo();
		List<Map<String, Object>> executeTimeList = iSchemeInfoService.getRealExecuteTime(taskId, schemeId, 
				executeTaskId, executeDate);
		resultPojo.setResultList(executeTimeList);
		return resultPojo;
	}
	
}
